package me.suntao.javaio.server.bio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 阻塞IO+线程池
 * Created by suntao on 2017/6/2.
 */
public class ThreadPoolEchoServer {
  private static final int DEFAULT_PORT = 28000;
  static final ExecutorService threadPool = Executors.newFixedThreadPool(5);
  public static void main(String[] args){
    Socket clientSocket = null;
    try (ServerSocket serverSocket = new ServerSocket(DEFAULT_PORT)) {
      while (true){
        clientSocket = serverSocket.accept();
        threadPool.submit(new EchoServerHandler(clientSocket));
      }
    }catch (IOException e){
      e.printStackTrace();
    }
  }
}
